<?php
declare (strict_types = 1);

namespace app\admin\validate\admin;

use think\Validate;

class Admin extends Validate
{
    /**
     * 定义验证规则
     * 格式：'字段名'	=>	['规则1','规则2'...]
     *
     * @var array
     */
    //'nickname', 'sex', 'come_date',
    //            'contract_date', 'campus_id', 'phone', 'idcard', 'pluralist', 'roles'
    protected $rule = [
        'username|用户名' => 'require',
        'password|密码' => 'require|min:6',
        'nickname|昵称' => 'require',
        'roles|角色' => 'require',
        'campus_id|校区' => 'require|number|gt:0',
        'sex|性别' => 'require|in:1,2',
        'come_date|聘用日期' => 'require|date',
        'contract_date|合同到期' => 'require|date',
        'phone|电话' => 'require|mobile',
        'idcard|身份证' => 'require|length:18',
        'pluralist|是否兼职' => 'require|in:1,2',
        'birthday|生日' => 'date',
        'academic|学历' => 'in:0,1,2,3,4,5,6,7,8',
        'contacts_name|联系人姓名' => 'chs|length:2,255',
        'contacts_relation|联系人关系' => 'length:1,255',
        'contacts_phone|联系人电话' => 'mobile',
        'contacts_addr|联系人地址' => 'length:1,255',
    ];

    /**
     * 定义错误信息
     * 格式：'字段名.规则名'	=>	'错误信息'
     *
     * @var array
     */
    protected $message = [
        'campus_id.gt' => '请选择校区',
        'idcard.length' => '身份证格式错误',
        'username.unique' => '账号已存在'
    ];

    /**
     * 登录
     */
    public function sceneLogin()
    {
        if(0){
            return $this->only(['username','password','captcha'])->append('captcha|验证码', 'require|captcha');
        }else{
            return $this->only(['username','password'])->append('captcha|验证码', 'require|captcha');
        }
    }

    /**
     * 添加
     */
    public function sceneAdd()
    {
        return $this->only(['username','password','nickname','roles'])
            ->append('username', 'unique:admin_user');
    }

    /**
     * 编辑
     */
    public function sceneEdit()
    {
        return $this->only(['username','nickname'])
        ->append('username', 'unique:admin_user');
    }

    /**
     * 编辑
     */
    public function sceneStaffadd()
    {
        return $this->only(['nickname', 'sex', 'come_date',
            'contract_date', 'campus_id', 'phone', 'idcard', 'pluralist', 'roles'])
            ->append('username', 'unique:admin_user');
    }

    public function sceneStaffedit()
    {
        return $this->only(['nickname', 'sex', 'come_date',
            'contract_date', 'campus_id', 'phone', 'idcard', 'pluralist', 'roles'])
            ->append('username', 'unique:admin_user');
    }

    /**
     * 添加
     */
    public function sceneCreateAccount()
    {
        return $this->only(['username','password','id'])
            ->append('username', 'unique:admin_user')
            ->append('id', 'require');
    }

    /**
     * 操作联系人
     * @return Admin
     */
    public function sceneStaffcontacts()
    {
        return $this->only(['contacts_name','contacts_relation','contacts_phone', 'contacts_addr']);
    }

        /**
     * 开发工单添加
     */
    public function sceneTaskadd()
    {
        return $this->only(['title','content']);
    }

    /**
     * 开发工单编辑
     */
    public function sceneTaskedit()
    {
        return $this->only(['title','content']);
    }

}
